$(function(){
    showPharmacyList();
});

function showPharmacyList(){
    API.table_get('pharmacy_category',{pharmacy:getParam('pharmacy'),p:getParam('p')},doShowCate);
}

var doShowCate = function(table_name,msg,getStatus){
    console.log(msg);
    if(getStatus){
        table_obj = $('#cate_table');
        //对相应的数据进行展示
        if(msg.length == 0){
            getNoneReplay();
            return false;
        }else{
            $('#has_no_msg').parent().empty();
            for(var i=0 ;i<msg.cate_list.length;i++){
                temp = msg.cate_list[i];
                tr = '<tr>';
                tr += '<td>' + temp.name +'</td>';
                tr += '<td>' + temp.drug_count + '</td>';
                tr += '<td>' + temp.created_at + '</td>';
                tr += '<td><a href="javascript:void(0);" onclick="showCateDrugs($(this));" data-id="' + temp.category_id + '">点击查看</a> </td>';
                tr += '</tr>';
                table_obj.append(tr);
            }
        }
        //分页
        $('#page').createPage({
            pageCount:Math.ceil(msg.drug_count/20),
            current:parseInt(getParam('p')),
            backFn: function (p) {
                window.location.href = window.location.href.replace('p='+getParam('p'),'p='+p);
            }
        })
    }else{
        getNoneReplay();
    }
};

function showCateDrugs(e){

    cid = e.attr('data-id');
    if(cid){
        window.location.href = './cate_drug.html?pharmacy='+getParam('pharmacy') + '&p=1' + '&cid='+cid;
    }

}


